<template>
    <div>
<table>
    <tbody>
        <tr>
            <td>项目名称</td>
            <td>
                <input type="text" name="" v-model="date.hname" id="">
            </td>
        </tr>
        <tr>
            <td>佣金</td>
            <td>
                <input type="text" name="" v-model="date.price" id="">
            </td>
        </tr>
        <tr>
            <td>状态</td>
            <td>
                <input type="checkbox" name="" v-model="date.state" id="">
            </td>
        </tr>
        <tr>
            <td>服务人数</td>
            <td>
                <input type="text" name="" v-model="date.num" id="">
            </td>
        </tr>
        <tr>
            <td>服务时长</td>
            <td>
                <input type="text" name="" v-model="date.time" id="">
            </td>
        </tr>
        <tr>
            <td colspan="2">
<input type="button" value="保存" @click="add">
            </td>
           
        </tr>
    </tbody>
</table>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';

const router=useRouter()
const add=()=>{
    if(date.value.hname==""){
        alert('项目名称不能为空')
        return;
    }
    if(date.value.price==0){
        alert('佣金不能为空')
        return;
    }
    
    
    if(date.value.num==0){
        alert('服务人数不能为空')
        return;
    }
    if(date.value.time==0){
        alert('服务时长不能为空')
        return;
    }


    axios.post('https://localhost:7167/api/Hospital/Add',date.value).then(res=>{
        if(res.data>0){
            alert('成功')
router.push({path:"/"})
        }else{
            alert('失败')
        }
    })
}
const date=ref({
    "hid": 0,
  "number": "",
  "price": 0,
  "hname": "",
  "isdel": true,
  "state": true,
  "num": 0,
  "time":  0
})
</script>

<style scoped>

</style>